/**
 * Created by Administrator on 2017/3/21.
 */
import React, {Component} from 'react';
import { Form, Button, Badge, Select, DatePicker, Radio, Descriptions, Input, Upload, Icon, TreeSelect } from 'antd';
import {connect} from 'dva';
import moment from 'moment'
import request from '@/utils/request';

const { TextArea } = Input;
const { Option } = Select;
const TreeNode = TreeSelect.TreeNode;

const ButtonGroup = Button.Group;
class AddPoliciesForm extends Component {
  constructor(props) {
    super(props);
    this.state = {
      all_staffs:[],
      all_organizations:[],
      format:'YYYY-MM-DD'
    };
  }
  componentDidMount() {
    const that=this;
    request(`/all_organizations`, {
      method: 'GET',
    }).then((response)=> {
      if(response.status===200){
        that.setState({
          all_organizations:response.data.data
        })
      }
    })
    this.fetAllUser()
  }
  fetAllUser=(type,value)=>{
    const that=this;
    request(`/all_staffs`, {
      method: 'GET',
    }).then((response)=> {
      console.log('all_structures', response)
      if(response.status===200){
        that.setState({
          all_staffs:response.data.data
        })
      }
    })
  }
  renderTreeNodes = data =>
    data.map((item,index) => {

      if (item.children.length>0) {
        return (
          <TreeNode value={item.id} title={item.name} key={item.id+index} >
            {this.renderTreeNodes(item.children)}
          </TreeNode>
        );
      }
      return <TreeNode  value={item.id}   key={item.id+index}  title={item.name}  />;
    });
  render() {
    const {getFieldDecorator} = this.props.form;
    return (
      <div>
        <Form>
          <Descriptions className={'blue-descriptions'} title={<div style={{textAlign:'center'}}>基本信息</div>} bordered>
            <Descriptions.Item label="系统帐号" span={1}>
              {getFieldDecorator('user_id', {
                initialValue: this.props.editRecord?this.props.editRecord.user_id:'',
              })(
                <Select >
                  {
                    this.state.all_staffs.map((item,index)=>{
                      return <Option key={index} value={item.id}>
                        {item.name}
                      </Option>
                    })
                  }
                </Select>
              )}
            </Descriptions.Item>
            <Descriptions.Item label="党员姓名" span={1}>
              {getFieldDecorator('name', {
                initialValue:this.props.editRecord?this.props.editRecord.name:'',
              })(
                <Input />
              )}
            </Descriptions.Item>
            <Descriptions.Item label="所属组织" span={1}>
              {getFieldDecorator('organization_id', {
                initialValue:this.props.editRecord?this.props.editRecord.organization_id:'',
              })(
                <TreeSelect
                  treeDefaultExpandAll
                  allowClear
                  dropdownStyle={{ maxHeight: 400, overflow: 'auto' }}
                >
                  {this.renderTreeNodes(this.state.all_organizations)}
                </TreeSelect>
              )}

            </Descriptions.Item>

            <Descriptions.Item label="民族" span={1}>
              {getFieldDecorator('nationality', {
                initialValue:this.props.editRecord?this.props.editRecord.nationality:'',
              })(
                <Input />
              )}
            </Descriptions.Item>
            <Descriptions.Item label="籍贯" span={1}>
              {getFieldDecorator('hometown', {
                initialValue:this.props.editRecord?this.props.editRecord.hometown:'',
              })(
                <Input />
              )}
            </Descriptions.Item>
            <Descriptions.Item label="性别" span={1}>
              {getFieldDecorator('sex', {
                initialValue:this.props.editRecord?this.props.editRecord.sex:'男',
              })(
                <Radio.Group>
                  <Radio value="男">男</Radio>
                  <Radio value="女">女</Radio>
                </Radio.Group>
              )}
            </Descriptions.Item>
            <Descriptions.Item label="身份证号码" span={1}>
              {getFieldDecorator('identity_number', {
                initialValue:this.props.editRecord?this.props.editRecord.identity_number:'',
              })(
                <Input />
              )}
            </Descriptions.Item>
            <Descriptions.Item label="生日" span={1}>
              {getFieldDecorator('birthday', {
                initialValue:this.props.editRecord?this.props.editRecord.birthday:'',
              })(
                <Input />
              )}
            </Descriptions.Item>
            <Descriptions.Item label="年龄" span={1}>
              {getFieldDecorator('age', {
                initialValue:this.props.editRecord?this.props.editRecord.age:'',
              })(
                <Input />
              )}
            </Descriptions.Item>
            <Descriptions.Item label="入党时间" span={1}>
              {getFieldDecorator('join_party_time', {
                initialValue:this.props.editRecord?this.props.editRecord.join_party_time?moment(this.props.editRecord.join_party_time):'': '',
              })(
                <DatePicker  style={{width:'100%'}}/>
              )}
            </Descriptions.Item>
            <Descriptions.Item label="党内职务" span={1}>
              {getFieldDecorator('party_position', {
                initialValue:this.props.editRecord?this.props.editRecord.party_position:'',
              })(
                <Input />
              )}
            </Descriptions.Item>
            <Descriptions.Item label="党内职务任职时间" span={1}>
              {getFieldDecorator('party_work_start_time', {
                initialValue:this.props.editRecord?this.props.editRecord.party_work_start_time?
                  moment(this.props.editRecord.party_work_start_time):'': '',
              })(
                <DatePicker  style={{width:'100%'}}/>
              )}
            </Descriptions.Item>
            <Descriptions.Item label="应缴党费" span={1}>
              {getFieldDecorator('party_fee', {
                initialValue:this.props.editRecord?this.props.editRecord.party_fee:'',
              })(
                <Input />
              )}
            </Descriptions.Item>
            <Descriptions.Item label="行政职务" span={1}>
              {getFieldDecorator('position', {
                initialValue:this.props.editRecord?this.props.editRecord.position:'',
              })(
                <Input />
              )}
            </Descriptions.Item>
            <Descriptions.Item label="行政职务任职时间" span={1}>
              {getFieldDecorator('start_work_time', {
                initialValue:this.props.editRecord?this.props.editRecord.start_work_time?moment(this.props.editRecord.start_work_time):'': '',
              })(
                <DatePicker  style={{width:'100%'}}/>
              )}
            </Descriptions.Item>
            <Descriptions.Item label="学历" span={1}>
              {getFieldDecorator('education', {
                initialValue:this.props.editRecord?this.props.editRecord.education:'',
              })(
                <Input />
              )}
            </Descriptions.Item>
          </Descriptions>
          <Descriptions className={'blue-descriptions'} title={<div style={{textAlign:'center',marginTop:'10px'}}>发展历程</div>} bordered>
            <Descriptions.Item label="递交入党申请书时间" span={1}>
              {getFieldDecorator('application_time', {
                initialValue:this.props.editRecord?this.props.editRecord.application_time?moment(this.props.editRecord.application_time):"": '',
              })(
                <DatePicker  style={{width:'100%'}}/>
              )}
            </Descriptions.Item>
            <Descriptions.Item label="培养人" span={1}>
              {getFieldDecorator('train_people', {
                initialValue:this.props.editRecord?this.props.editRecord.train_people:'',
              })(
                <Input />
              )}
            </Descriptions.Item>
            <Descriptions.Item label="参加培训班时间" span={1}>
              {getFieldDecorator('join_training_course_time', {
                initialValue:this.props.editRecord?this.props.editRecord.join_training_course_time?
                  moment(this.props.editRecord.join_training_course_time):'': '',
              })(
                <DatePicker  style={{width:'100%'}}/>
              )}
            </Descriptions.Item>
            <Descriptions.Item label="第一次谈话时间" span={1}>
              {getFieldDecorator('first_talk_time', {
                initialValue:this.props.editRecord?this.props.editRecord.first_talk_time?
                  moment(this.props.editRecord.first_talk_time):'': '',
              })(
                <DatePicker  style={{width:'100%'}}/>
              )}
            </Descriptions.Item>
            <Descriptions.Item label="确定为入党积极分子时间" span={1}>
              {getFieldDecorator('determine_activists_time', {
                initialValue:this.props.editRecord?this.props.editRecord.determine_activists_time?
                  moment(this.props.editRecord.determine_activists_time):'': '',
              })(
                <DatePicker  style={{width:'100%'}}/>
              )}
            </Descriptions.Item>
            <Descriptions.Item label="第一季度思想汇报时间" span={1}>
              {getFieldDecorator('first_quarter_report_time', {
                initialValue:this.props.editRecord?this.props.editRecord.first_quarter_report_time?
                  moment(this.props.editRecord.first_quarter_report_time):'': '',
              })(
                <DatePicker  style={{width:'100%'}}/>
              )}
            </Descriptions.Item>
            <Descriptions.Item label="第二季度思想汇报时间" span={1}>
              {getFieldDecorator('secord_quarter_report_time', {
                initialValue:this.props.editRecord?this.props.editRecord.secord_quarter_report_time?
                  moment(this.props.editRecord.secord_quarter_report_time):'': '',
              })(
                <DatePicker  style={{width:'100%'}}/>
              )}
            </Descriptions.Item>
            <Descriptions.Item label="第三季度思想汇报时间" span={1}>
              {getFieldDecorator('third_quarter_report_time', {
                initialValue:this.props.editRecord?this.props.editRecord.third_quarter_report_time?
                  moment(this.props.editRecord.third_quarter_report_time):'': '',
              })(
                <DatePicker  style={{width:'100%'}}/>
              )}
            </Descriptions.Item>
            <Descriptions.Item label="第四季度思想汇报时间" span={1}>
              {getFieldDecorator('fourth_quarter_report_time', {
                initialValue:this.props.editRecord?this.props.editRecord.fourth_quarter_report_time?
                  moment(this.props.editRecord.fourth_quarter_report_time):'': '',
              })(
                <DatePicker  style={{width:'100%'}}/>
              )}
            </Descriptions.Item>
            <Descriptions.Item label="半年党支部考察时间" span={1}>
              {getFieldDecorator('half_year_investigation_time', {
                initialValue:this.props.editRecord?this.props.editRecord.half_year_investigation_time?
                  moment(this.props.editRecord.half_year_investigation_time):'': '',
              })(
                <DatePicker  style={{width:'100%'}}/>
              )}
            </Descriptions.Item>
            <Descriptions.Item label="确定发展对象时间" span={1}>
              {getFieldDecorator('determine_development_target_time', {
                initialValue:this.props.editRecord?this.props.editRecord.determine_development_target_time?
                  moment(this.props.editRecord.determine_development_target_time):'': '',
              })(
                <DatePicker  style={{width:'100%'}}/>
              )}
            </Descriptions.Item>
            <Descriptions.Item label="入党介绍人" span={1}>
              {getFieldDecorator('introducer', {
                initialValue:this.props.editRecord?this.props.editRecord.introducer:'',
              })(
                <Input/>
              )}
            </Descriptions.Item>
            <Descriptions.Item label="支部大会通过为预备时间" span={1}>
              {getFieldDecorator('determine_preparation_time', {
                initialValue:this.props.editRecord?this.props.editRecord.determine_preparation_time?
                  moment(this.props.editRecord.determine_preparation_time):'': '',
              })(
                <DatePicker  style={{width:'100%'}}/>
              )}
            </Descriptions.Item>
            <Descriptions.Item label="转为正式党员时间" span={1}>
              {getFieldDecorator('regularization_time', {
                initialValue:this.props.editRecord?this.props.editRecord.regularization_time?
                  moment(this.props.editRecord.regularization_time):'': '',
              })(
                <DatePicker  style={{width:'100%'}}/>
              )}
            </Descriptions.Item>
          </Descriptions>
        </Form>

      </div>
    );
  }
}

const AddPoliciesFormWrap = Form.create()(AddPoliciesForm);
export default connect()(AddPoliciesFormWrap);


